package cn.xeblog.plugin.tools.read;

import cn.xeblog.plugin.annotation.DoTool;
import cn.xeblog.plugin.tools.AbstractTool;
import cn.xeblog.plugin.tools.Tools;
import cn.xeblog.plugin.tools.read.page.BookshelfPage;
import cn.xeblog.plugin.tools.read.page.DirectoryPage;
import cn.xeblog.plugin.tools.read.page.ReadPage;
import cn.xeblog.plugin.tools.read.page.SettingPage;
import cn.xeblog.plugin.tools.read.page.StartPage;
import cn.xeblog.plugin.tools.read.page.UIManager;

/**
 * 阅读器
 *
 * @author LYF
 * @date 2022-07-18
 */
@DoTool(Tools.READ)
public class Read extends AbstractTool {

  @Override
  protected void init() {

    mainPanel.removeAll();
    mainPanel.setLayout(null);
    // 启用并可见
    mainPanel.setEnabled(true);
    mainPanel.setVisible(true);

    // 初始化属性
    UIManager.mainPanel = mainPanel;
    UIManager.startPage = new StartPage();
    UIManager.settingPage = new SettingPage();
    UIManager.bookshelfPage = new BookshelfPage();
    UIManager.directoryPage = new DirectoryPage();

    // 开始页展示
    UIManager.startPage.show();
  }

  @Override
  public void over() {
    super.over();
    ReadPage readPage = UIManager.readPage;
    if (readPage != null) {
      // 释放Window及其子组件及其所有子组件使用的所有本机屏幕资源
      readPage.dispose();
    }
  }
}
